package core.controller.cmds;

import core.controller.CommandController;
import core.dal.AdminFunctionality;
import core.dto.IOperatorDTO;
import exceptions.UserNotFoundException;

public class ShowUserCMD implements ICmd{

	AdminFunctionality functionality;
	final String level = "Admin";
	ICmd nextCMD;
	
	CommandController cc;
	
	public ShowUserCMD(CommandController commandController, AdminFunctionality aF){
		this.cc = commandController;
		functionality = aF;
	}
	
	@Override
	public void setNextCmd(ICmd nextCmd) {
		nextCMD = nextCmd;
		
	}

	@Override
	public void execute(String cmd){
		if (cmd.equals("showUser")) {
			int id;
			
			cc.getTUI().showOutput("Enter user ID");
			id = Integer.parseInt(cc.getTUI().getInput());
			
			try {
				IOperatorDTO user = functionality.showUser(id);
				
				cc.getTUI().showOutput("ID: " + String.valueOf((user.getOprId())));
				cc.getTUI().showOutput("CPR: " + user.getCpr());
				cc.getTUI().showOutput("NAVN: " + user.getOprNavn());
				cc.getTUI().showOutput("PASS: " + user.getPassword());

			} catch (UserNotFoundException e) {
				cc.getTUI().showOutput(e.getMessage());
			}

			
		}

		
		if (nextCMD != null) {
			nextCMD.execute(cmd);
		}
	}

	@Override
	public String getInfo() {
		return "showUser - Show a specific user";
		
	}

	@Override
	public String getLevel() {
		return this.level;
		
	}
}
